package cn.itcast.nio.c1;

import java.nio.ByteBuffer;

import static cn.itcast.nio.c1.ByteBufferUtil.debugAll;

public class TestByteBufferRead {
    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(10);
        buffer.put(new byte[]{'a','b','c','d'});
        buffer.flip();

        //rewind 从头开始读取,将postion重新设为0
        /*buffer.get(new byte[4]);
        debugAll(buffer);
        buffer.rewind();
        System.out.println((char) buffer.get());*/

        /*System.out.println((char) buffer.get());
        System.out.println((char) buffer.get());

        //mark是做一个标记postition，reset是将位置重新定位到position的位置
        buffer.mark();
        System.out.println((char) buffer.get());
        System.out.println((char) buffer.get());
        //重置位置
        buffer.reset();
        System.out.println((char) buffer.get());
        System.out.println((char) buffer.get());*/

        //get（i）不会改变position位置
        System.out.println((char) buffer.get(3));
        debugAll(buffer);


    }
}
